package com.becca.cake.core.rule.fixingsRule;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.becca.cake.model.system.DataDictionaryDO;
import com.becca.cake.util.DateUtils;

/**
 * 配送时间规则帮助类
 * @copyright  尊星(上海)信息科技有限公司
 * @author hejinguo
 * @date 2016年6月14日 上午11:03:44
 */
public class FixingsRuleHelp {
    /**
     * 获取配送时间
     * @param fixingRule
     * @return
     */
    public static Map<String, Object> getFixingTime(String fixingRule,
                                                    List<DataDictionaryDO> listDictionaryModels) {
        //返回对象
        Map<String, Object> returnMap = new HashMap<String, Object>();
        //step1:获取当前年月日
        String todayDate = DateUtils.getTodayDate();
        Date nowDate = DateUtils.getDateToday();
        //step3:时间规则  15:59:59&1;16:00:00&2  当前时间前的加1天,这个时间后的加2天
        String[] ruleArray = fixingRule.split(";");
        for (String rule : ruleArray) {
            String[] conditionArray = rule.split("&");
            String[] dataTimeBetweet = conditionArray[0].split("-");
            String startFixingsDateStr = todayDate + " " + dataTimeBetweet[0];
            String endFixingsDateStr = todayDate + " " + dataTimeBetweet[1];
            Date startFixingsDate = DateUtils.toLongDateTime(startFixingsDateStr);
            Date endFixingsDate = DateUtils.toLongDateTime(endFixingsDateStr);
            if (startFixingsDate.before(nowDate) && endFixingsDate.after(nowDate)) {//在当前系统之前的
                returnMap.put("shortDate", DateUtils.dtSimpleFormat(DateUtils
                    .getSomeDayDate(Integer.valueOf(conditionArray[1]))));
                returnMap.put("times", listDictionaryModels.get(0).getKeyes());//下午 3点后送达
                return returnMap;
            }
        }
        return returnMap;
    }

    public static void main(String[] args) {
        List<DataDictionaryDO> listDictionaryModels = new ArrayList<DataDictionaryDO>();
        DataDictionaryDO model = new DataDictionaryDO();
        model.setKeyes("10:00~12:00");
        model.setValue("10:00~12:00");
        listDictionaryModels.add(model);
        Map<String, Object> retuMap = getFixingTime("15:59:59&1;16:00:00&2", listDictionaryModels);
        System.out.println(retuMap.get("shortDate") + "------" + "times:" + retuMap.get("times"));
    }
}
